package com.zq.blog.service.impl;

import com.zq.blog.dao.UserRepository;
import com.zq.blog.po.User;
import com.zq.blog.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class UserService implements com.zq.blog.service.UserService {

    @Autowired
    UserRepository userRepository;

    @Override
    public User checkUser(String username, String password) {

        User user = new User();
        user.setUsername(username);
        user.setPassword(MD5Utils.code(password));

        Example<User> of = Example.of(user);
        Optional<User> one = userRepository.findOne(of);

        return one.get();

    }
}
